< previous page page_407 next page >

Page 407
e10a6a0a59f035e870d90cca05b85fce.gif
' Apply a transformation object's Transform
' method to the points.
Public Sub TwoDObject_ApplyTransformationObject( _
    ByRef obj As Transformation)
Dim i As Integer

    For i = 1 To m_NumPoints 
        obj.Transform m_Points(i).X, m_Points(i).Y
    Next i
End Sub
Using transformation objects, you can create a transformation that is the composition of two other transformations. If TransWave and TransTwist are two transformation classes, you could use the following Visual Basic code to create a class representing a TransWave transformation followed by a TransTwist transformation.
e10a6a0a59f035e870d90cca05b85fce.gif
Option Explicit
' A TransWave followed by a TransTwist.

Implements Transformation

' The sub-transformations.
Public wave As New TransWave
Public twist As New TransTwist

' Transform the point (X, Y).
Private Sub Transformation_Transform(X As Single, Y As Single)
Dim obj As Transformation

    ' Apply the wave transformation.
    Set obj = wave
    obj.Transform X, Y

    ' Apply the twist transformation.
    Set obj = twist
    obj.Transform X, Y
End Sub
Treating Types of Transformation Differently
Using transformation objects, you can easily manipulate shape-distorting transformations. You could even use these techniques to store the matrix transformations described earlier as transformation objects. You could place a transformation matrix inside one of these objects and make the object's Transform subroutine transform points by applying the matrix. There are a couple of reasons you should treat these two kinds of transformations differently.
First, invoking the Transform subroutine of a transformation object adds an extra subroutine call to the transformation process. To make matters worse, that subroutine call

 
< previous page page_407 next page >